Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports Bring2mind.DNN.Modules.UserFiles.Business

Namespace Bring2mind.DNN.Modules.UserFiles.Controls

 Public Class UserFilesOptions
  Inherits DotNetNuke.Entities.Modules.ModuleSettingsBase

#Region " Web Form Designer Generated Code "

  'This call is required by the Web Form Designer.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub
  Protected WithEvents txtMaxFileLength As System.Web.UI.WebControls.TextBox
  Protected WithEvents Comparevalidator1 As System.Web.UI.WebControls.CompareValidator
  Protected WithEvents Requiredfieldvalidator1 As System.Web.UI.WebControls.RequiredFieldValidator
  Protected WithEvents txtUserQuota As System.Web.UI.WebControls.TextBox
  Protected WithEvents Comparevalidator2 As System.Web.UI.WebControls.CompareValidator
  Protected WithEvents Requiredfieldvalidator2 As System.Web.UI.WebControls.RequiredFieldValidator
  Protected WithEvents txtMaxImageSize As System.Web.UI.WebControls.TextBox
  Protected WithEvents Comparevalidator3 As System.Web.UI.WebControls.CompareValidator
  Protected WithEvents Requiredfieldvalidator3 As System.Web.UI.WebControls.RequiredFieldValidator
  Protected WithEvents txtGridSize As System.Web.UI.WebControls.TextBox
  Protected WithEvents Comparevalidator4 As System.Web.UI.WebControls.CompareValidator
  Protected WithEvents Requiredfieldvalidator4 As System.Web.UI.WebControls.RequiredFieldValidator
  Protected WithEvents txtValidExtensions As System.Web.UI.WebControls.TextBox

  'NOTE: The following placeholder declaration is required by the Web Form Designer.
  'Do not delete or move it.
  Private designerPlaceholderDeclaration As System.Object

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
   'CODEGEN: This method call is required by the Web Form Designer
   'Do not modify it using the code editor.
   InitializeComponent()
  End Sub

#End Region

#Region " Base Method Implementations "
  Public Overrides Sub LoadSettings()
   Try
    If Not Page.IsPostBack Then
     Dim Settings As New ModuleSettings(ModuleId)
     With Settings
      txtMaxFileLength.Text = (.MaxFileLength / 1000).ToString
      txtUserQuota.Text = (.UserQuota / 1000).ToString
      txtMaxImageSize.Text = .MaxImageSize.ToString
      txtGridSize.Text = .GridSize.ToString
      txtValidExtensions.Text = .ValidExtensions
     End With
    End If
   Catch exc As Exception
    DotNetNuke.Services.Exceptions.ProcessModuleLoadException(Me, exc)
   End Try
  End Sub

  Public Overrides Sub UpdateSettings()
   Try

    Dim Settings As New ModuleSettings(ModuleId)
    With Settings
     .MaxFileLength = Integer.Parse(txtMaxFileLength.Text) * 1000
     .UserQuota = Integer.Parse(txtUserQuota.Text) * 1000
     .MaxImageSize = Integer.Parse(txtMaxImageSize.Text)
     .GridSize = Integer.Parse(txtGridSize.Text)
     .ValidExtensions = txtValidExtensions.Text.Replace(",", ";")
     If Right(.ValidExtensions, 1) <> ";" Then
      .ValidExtensions &= ";"
     End If
     .SaveSettings()
    End With
    Dim CacheKey As String = "Settings4Module" & Me.ModuleId & "inPortal" & Me.PortalId
    Me.Cache.Remove(CacheKey)

   Catch exc As Exception
    DotNetNuke.Services.Exceptions.ProcessModuleLoadException(Me, exc)
   End Try
  End Sub

#End Region

 End Class

End Namespace
